package com.shareppy.nomrnaui.util;

import java.util.Random;

import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.media.RingtoneManager;
import android.support.v4.app.NotificationCompat;

public class NotificationUtil {

	private static NotificationManager notificationManager;

	private NotificationUtil() {
		super();
	}

	public static int pushNotification(//
			Context context, //
			PendingIntent pendingIntent,//
			String title,//
			String text, //
			int number, //
			int ledColor//
	) {
		int nottyId = new Random().nextInt(1000000);
		return pushNotification(context, pendingIntent, title, text,
				android.R.drawable.ic_dialog_alert, number, ledColor, nottyId);
	}

	public static int pushNotification(//
			Context context, //
			PendingIntent pendingIntent, //
			String title, //
			String text, //
			int bigIcon,//
			int number, //
			int ledColor, //
			int nottyId//
	) {
		NotificationCompat.Builder builder = new NotificationCompat.Builder(
				context);
		builder//
		.setContentTitle(title)//
				.setContentText(text)//
				.setSmallIcon(bigIcon)
				//
				.setSound(
						RingtoneManager
								.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))//
				.setLights(ledColor, 1000, 1000);
		if (number != -1) {
			builder.setNumber(number);
		}
		if (pendingIntent != null) {
			builder.setContentIntent(pendingIntent);
		}
		getNotificationManager(context).notify(nottyId, builder.build());
		return nottyId;
	}

	public static NotificationManager getNotificationManager(Context context) {
		if (notificationManager == null) {
			notificationManager = (NotificationManager) context
					.getSystemService(Context.NOTIFICATION_SERVICE);
		}
		return notificationManager;
	}
}